require('../../assets/css/index.less')
require('./forgot.less')
// 引入axios
const request = require('../../assets/js/requers.js')
//1定义变量引入验证码差价
const CaptchaMini = require('captcha-mini')
// 获取元素

const phoneIpt = document.querySelector('#phoneIpt')
const codeIpt = document.querySelector('#codeIpt')
const psdIpt = document.querySelector('#psdIpt')
const psdTwinsIpt = document.querySelector('#psdTwinsIpt')
const submitBtn = document.querySelector('#submitBtn')


//dom加载完毕
window.onload = () => {
    /*不传值，统一配置默认值
    */
    //创建验证码实例对象，配置字体大小
    let captcha1 = new CaptchaMini({
        fontSize: 60,
        dotNum: 100,
        length: 4,
    })
    //3
    let codeImg=''
    captcha1.draw(document.querySelector('.codeImg'), r => {
        //打印r
        console.log(r, '验证码1');
        codeImg = r
    })
    //判断信息    

    // 注册事件
    submitBtn.addEventListener('click', () => {
        // 定义错误提示
        let errMsg = '';
        console.log(codeIpt.value);
        console.log(codeImg);
        if (!/^1[3-9]\d{9}$/.test(phoneIpt.value)) {
            errMsg = '手机号不正确'

        } else if (codeIpt.value.toLowerCase() !== codeImg.toLowerCase()) {

            errMsg = '验证码不正确'
        } else if (!/^\w{3,6}$/.test(psdIpt.value)) {
            errMsg = '密码3-6位'
        } else if (psdTwinsIpt.value !== psdIpt.value) {
            errMsg = '密码不一致'
        } else {
            console.log('验证成功，可以发送请求');
            // 请求
            request.post('/api/user/isExist', {
                account: phoneIpt.value,
            })
            .then(res => {
                    // 结构数据
                    let { errno, message } = res.data
                    // 判断
                    if (errno === 0) {
                        // 发送请求
                        request.post('/api/user/changelnfo',{
                            
                        }).then(res=>{
                            
                        })
                    } else {
                        // 弹出错误信息
                        alert(message)
                    }
                })
                .catch(res => {

                })
                
        }

        // 弹窗
        if (errMsg) {
            alert(errMsg)
        }



    })









}